package com.lmc.base.demo.ai.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.openai.OpenAiChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Flux;

/**
 * @author lmc
 * @Description: TODO
 * @Create 2024-08-13 19:31
 * @version: 1.0
 */
@RestController
@RequestMapping("/open-ai")
@Slf4j
public class OpenAIController {

    @Resource
    private OpenAiChatClient openAiChatClient;

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping(path = "/chat", produces = "application/json;charset=utf-8")
    public String chat(String message) {

        String result = openAiChatClient.call(message);
        log.info(result);
        return result;
    }

    @RequestMapping(path = "/stream", produces = "application/json;charset=utf-8")
    public Flux<String> chatStream(String message) {

        return openAiChatClient.stream(message);
    }

}
